home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyo (Python 2.5) import exceptions import sys import optparse import os import warnings import traceback from os.path import isfile, join, split import ZSI from ConfigParser import ConfigParser from ZSI.generate.wsdl2python import WriteServiceModule, ServiceDescription as wsdl2pyServiceDescription from ZSI.wstools import WSDLTools, XMLSchema from ZSI.wstools.logging import setBasicLoggerDEBUG from ZSI.generate import containers, utility from ZSI.generate.utility import NCName_to_ClassName as NC_to_CN, TextProtect from ZSI.generate.wsdl2dispatch import ServiceModuleWriter as ServiceDescription from ZSI.generate.wsdl2dispatch import WSAServiceModuleWriter as ServiceDescriptionWSA warnings.filterwarnings('ignore', '', exceptions.UserWarning) def SetDebugCallback(option, opt, value, parser, *args, **kwargs): setBasicLoggerDEBUG() warnings.resetwarnings() def SetPyclassMetaclass(option, opt, value, parser, *args, **kwargs): ServiceHeaderContainer = ServiceHeaderContainer TypecodeContainerBase = TypecodeContainerBase TypesHeaderContainer = TypesHeaderContainer import ZSI.generate.containers TypecodeContainerBase.metaclass = kwargs['metaclass'] TypesHeaderContainer.imports.append('from %(module)s import %(metaclass)s' % kwargs) ServiceHeaderContainer.imports.append('from %(module)s import %(metaclass)s' % kwargs) def SetUpLazyEvaluation(option, opt, value, parser, *args, **kwargs): TypecodeContainerBase = TypecodeContainerBase import ZSI.generate.containers TypecodeContainerBase.lazy = True def wsdl2py(args = None): op = optparse.OptionParser(usage = 'USAGE: %wsdl2py [options] WSDL', description = wsdl2py.__doc__) op.add_option('-x', '--schema', action = 'store_true', dest = 'schema', default = False, help = 'process just the schema from an xsd file [no services]') op.add_option('-d', '--debug', action = 'callback', callback = SetDebugCallback, help = 'debug output') op.add_option('-a', '--address', action = 'store_true', dest = 'address', default = False, help = 'ws-addressing support, must include WS-Addressing schema.') op.add_option('-b', '--complexType', action = 'callback', callback = SetPyclassMetaclass, callback_kwargs = { 'module': 'ZSI.generate.pyclass', 'metaclass': 'pyclass_type' }, help = 'add convenience functions for complexTypes, including Getters, Setters, factory methods, and properties (via metaclass). *** DONT USE WITH --simple-naming ***') op.add_option('-l', '--lazy', action = 'callback', callback = SetUpLazyEvaluation, callback_kwargs = { }, help = 'EXPERIMENTAL: recursion error solution, lazy evalution of typecodes') op.add_option('-w', '--twisted', action = 'store_true', dest = 'twisted', default = False, help = 'generate a twisted.web client/server, dependencies python>=2.4, Twisted>=2.0.0, TwistedWeb>=0.5.0') op.add_option('-o', '--output-dir', action = 'store', dest = 'output_dir', default = '.', type = 'string', help = 'save files in directory') op.add_option('-s', '--simple-naming', action = 'store_true', dest = 'simple_naming', default = False, help = 'map element names directly to python attributes') op.add_option('-p', '--pydoc', action = 'store_true', dest = 'pydoc', default = False, help = 'top-level directory for pydoc documentation.') is_cmdline = args is None if is_cmdline: (options, args) = op.parse_args() else: (options, args) = op.parse_args(args) if len(args) != 1: print >>sys.stderr, 'Expecting a file/url as argument (WSDL).' sys.exit(os.EX_USAGE) location = args[0] if options.schema is True: reader = XMLSchema.SchemaReader(base_url = location) else: reader = WSDLTools.WSDLReader() load = reader.loadFromFile if not isfile(location): load = reader.loadFromURL try: wsdl = load(location) except Exception: e = None print >>sys.stderr, 'Error loading %s: \n\t%s' % (location, e) traceback.print_exc(sys.stderr) if hasattr(os, 'EX_NOINPUT'): sys.exit(os.EX_NOINPUT) sys.exit('error loading %s' % location) if isinstance(wsdl, XMLSchema.XMLSchema): wsdl.location = location files = _wsdl2py(options, wsdl) else: files = _wsdl2py(options, wsdl) files.append(_wsdl2dispatch(options, wsdl)) if getattr(options, 'pydoc', False): _writepydoc(os.path.join('docs', 'API'), *files) if is_cmdline: return None return files def _wsdl2py(options, wsdl): if options.twisted: ServiceHeaderContainer = ServiceHeaderContainer import ZSI.generate.containers try: ServiceHeaderContainer.imports.remove('from ZSI import client') except ValueError: pass ServiceHeaderContainer.imports.append('from ZSI.twisted import client') if options.simple_naming: containers.SetTypeNameFunc((lambda n: '%s_' % NC_to_CN(n))) containers.SetElementNameFunc((lambda n: '%s' % NC_to_CN(n))) containers.ContainerBase.func_aname = lambda instnc, n: TextProtect(str(n)) utility.namespace_name = lambda cls, ns: utility.Namespace2ModuleName(ns) files = [] append = files.append if isinstance(wsdl, XMLSchema.XMLSchema): wsm = WriteServiceModule(_XMLSchemaAdapter(wsdl.location, wsdl), addressing = options.address) else: wsm = WriteServiceModule(wsdl, addressing = options.address) client_mod = wsm.getClientModuleName() client_file = join(options.output_dir, '%s.py' % client_mod) append(client_file) fd = open(client_file, 'w+') wsm.writeClient(fd) fd.close() types_mod = wsm.getTypesModuleName() types_file = join(options.output_dir, '%s.py' % types_mod) append(types_file) fd = open(types_file, 'w+') wsm.writeTypes(fd) fd.close() return files def _wsdl2dispatch(options, wsdl): kw = dict() if options.twisted: WSResource = WSResource import ZSI.twisted.WSresource kw['base'] = WSResource ss = ServiceDescription(**kw) if options.address is True: raise RuntimeError, 'WS-Address w/twisted currently unsupported, edit the "factory" attribute by hand' elif options.address is True: ss = ServiceDescriptionWSA() else: ss = ServiceDescription(**kw) ss.fromWSDL(wsdl) file_name = ss.getServiceModuleName() + '.py' fd = open(join(options.output_dir, file_name), 'w+') ss.write(fd) fd.close() return file_name class _XMLSchemaAdapter: def __init__(self, location, schema): self.name = '_'.join(split(location)[-1].split('.')) self.types = { schema.targetNamespace: schema } import os import pydoc import sys import warnings import inspect import os.path as os from distutils import log from distutils.command.build_py import build_py from distutils.util import convert_path from ZSI.schema import ElementDeclaration, TypeDefinition def _writedoc(doc, thing, forceload = 0): try: (object, name) = pydoc.resolve(thing, forceload) page = pydoc.html.page(pydoc.describe(object), pydoc.html.document(object, name)) fname = os.path.join(doc, name + '.html') file = open(fname, 'w') file.write(page) file.close() except (ImportError, pydoc.ErrorDuringImport): value = None traceback.print_exc(sys.stderr) return name + '.html' def _writeclientdoc(doc, thing, forceload = 0): docmodule = pydoc.HTMLDoc.docmodule def strongarm(self, object, name = None, mod = (None,), *ignored): result = docmodule(self, object, name, mod, *ignored) nonmembers = [] push = nonmembers.append for k, v in inspect.getmembers(object, inspect.isclass): if inspect.getmodule(v) is not object and getattr(v, 'typecode', None) is not None: push('<a href="%s.html">%s</a>: pyclass alias<br/>' % (v.__name__, k)) continue result += self.bigsection('Aliases', '#ffffff', '#eeaa77', ''.join(nonmembers)) return result pydoc.HTMLDoc.docmodule = strongarm try: (object, name) = pydoc.resolve(thing, forceload) page = pydoc.html.page(pydoc.describe(object), pydoc.html.document(object, name)) name = os.path.join(doc, name + '.html') file = open(name, 'w') file.write(page) file.close() except (ImportError, pydoc.ErrorDuringImport): value = None log.debug(str(value)) pydoc.HTMLDoc.docmodule = docmodule def _writetypesdoc(doc, thing, forceload = 0): try: (object, name) = pydoc.resolve(thing, forceload) name = os.path.join(doc, name + '.html') except (ImportError, pydoc.ErrorDuringImport): value = None log.debug(str(value)) return None cdict = { } fdict = { } elements_dict = { } types_dict = { } for kname, klass in inspect.getmembers(thing, inspect.isclass): if thing is not inspect.getmodule(klass): continue cdict[kname] = inspect.getmembers(klass, inspect.isclass) for iname, iklass in cdict[kname]: key = (kname, iname) fdict[key] = _writedoc(doc, iklass) if issubclass(iklass, ElementDeclaration): try: typecode = iklass() except (AttributeError, RuntimeError): ex = None elements_dict[iname] = _writebrokedoc(doc, ex, iname) continue elements_dict[iname] = None if typecode.pyclass is not None: elements_dict[iname] = _writedoc(doc, typecode.pyclass) continue continue if issubclass(iklass, TypeDefinition): try: typecode = iklass(None) except (AttributeError, RuntimeError): ex = None types_dict[iname] = _writebrokedoc(doc, ex, iname) continue types_dict[iname] = None if typecode.pyclass is not None: types_dict[iname] = _writedoc(doc, typecode.pyclass) continue continue continue def strongarm(self, object, name = None, mod = None, funcs = None, classes = (None, None, None, { }, { }), *ignored): realname = object.__name__ if not name: pass name = realname bases = object.__bases__ (object, name) = pydoc.resolve(object, forceload) contents = [] push = contents.append if name == realname: title = '<a name="%s">class <strong>%s</strong></a>' % (name, realname) else: title = '<strong>%s</strong> = <a name="%s">class %s</a>' % (name, name, realname) mdict = { } if bases: parents = [] for base in bases: parents.append(self.classlink(base, object.__module__)) title = title + '(%s)' % pydoc.join(parents, ', ') doc = self.markup(pydoc.getdoc(object), self.preformat, funcs, classes, mdict) if doc: pass doc = '<tt>%s<br> </tt>' % doc for iname, iclass in cdict[name]: fname = fdict[(name, iname)] if elements_dict.has_key(iname): push('class <a href="%s">%s</a>: element declaration typecode<br/>' % (fname, iname)) pyclass = elements_dict[iname] if pyclass is not None: push('<ul>instance attributes:') push('<li><a href="%s">pyclass</a>: instances serializable to XML<br/></li>' % elements_dict[iname]) push('</ul>') pyclass is not None if types_dict.has_key(iname): push('class <a href="%s">%s</a>: type definition typecode<br/>' % (fname, iname)) pyclass = types_dict[iname] if pyclass is not None: push('<ul>instance attributes:') push('<li><a href="%s">pyclass</a>: instances serializable to XML<br/></li>' % types_dict[iname]) push('</ul>') pyclass is not None push('class <a href="%s">%s</a>: TODO not sure what this is<br/>' % (fname, iname)) contents = ''.join(contents) return self.section(title, '#000000', '#ffc8d8', contents, 3, doc) doclass = pydoc.HTMLDoc.docclass pydoc.HTMLDoc.docclass = strongarm try: page = pydoc.html.page(pydoc.describe(object), pydoc.html.document(object, name)) file = open(name, 'w') file.write(page) file.close() except (ImportError, pydoc.ErrorDuringImport): value = None log.debug(str(value)) pydoc.HTMLDoc.docclass = doclass def _writebrokedoc(doc, ex, name, forceload = 0): try: fname = os.path.join(doc, name + '.html') page = pydoc.html.page(pydoc.describe(ex), pydoc.html.document(str(ex), fname)) file = open(fname, 'w') file.write(page) file.close() except (ImportError, pydoc.ErrorDuringImport): value = None log.debug(str(value)) return name + '.html' def _writepydoc(doc, *args): ok = True if not os.path.isdir(doc): os.makedirs(doc) if os.path.curdir not in sys.path: sys.path.append(os.path.curdir) for f in args: if f.startswith('./'): f = f[2:] name = os.path.sep.join(f.strip('.py').split(os.path.sep)) try: e = __import__(name) except Exception: ex = None raise if name.endswith('_client'): _writeclientdoc(doc, e) continue if name.endswith('_types'): _writetypesdoc(doc, e) continue try: _writedoc(doc, e) continue except IndexError: ex = None _writebrokedoc(doc, ex, name) continue continue